package com.glory.eapequipmentmonitor.fragment;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;

import com.glory.eapequipmentmonitor.R;
import com.glory.eapequipmentmonitor.activity.AbortActivity;
import com.glory.eapequipmentmonitor.activity.ChangeThingListActivity;
import com.glory.eapequipmentmonitor.activity.CheckActivity;
import com.glory.eapequipmentmonitor.activity.EndWorkActivity;
import com.glory.eapequipmentmonitor.activity.EqpRepairActivity;
import com.glory.eapequipmentmonitor.activity.IntoDepotActivity;
import com.glory.eapequipmentmonitor.activity.PackPackageActivity;
import com.glory.eapequipmentmonitor.activity.SearchDepotActivity;
import com.glory.eapequipmentmonitor.activity.SearchEqpActivity;
import com.glory.eapequipmentmonitor.activity.SearchLotActivity;
import com.glory.eapequipmentmonitor.activity.SettingActivity;
import com.glory.eapequipmentmonitor.activity.StartWorkActivity;
import com.glory.eapequipmentmonitor.activity.TakePartActivity;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseFragment;
import com.pda.platform.ui.ui_pdaplatform.convenient_banner.CBViewHolderCreator;
import com.pda.platform.ui.ui_pdaplatform.convenient_banner.ConvenientBanner;
import com.pda.platform.ui.ui_pdaplatform.convenient_banner.ImageHolderView;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import butterknife.Unbinder;

public class IndexFragment extends FreeUI_BaseFragment {

    @BindView(R.id.cyclicImageView)
    ConvenientBanner convenientBanner;
//    @BindView(R.id.flipper)
//    ViewFlipper flipper;

    List<String> imgList = new ArrayList<String>();
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    Unbinder unbinder;
    Unbinder unbinder1;

    public IndexFragment() {
        // Required empty public constructor
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_index;
    }

    @Override
    protected void initView() {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) convenientBanner.getLayoutParams();
        lp.width = FreeApi_StaticMembers.SCREEN_WIDTH;
        lp.height = FreeApi_StaticMembers.SCREEN_WIDTH * 11 / 25;
        convenientBanner.setLayoutParams(lp);


        imgList.add("res://com.glory.eapequipmentmonitor/"+ R.drawable.banner1);
        imgList.add("res://com.glory.eapequipmentmonitor/"+ R.drawable.banner2);
        imgList.add("res://com.glory.eapequipmentmonitor/"+ R.drawable.banner3);
        imgList.add("res://com.glory.eapequipmentmonitor/"+ R.drawable.banner4);
        convenientBanner.setPages(
                new CBViewHolderCreator<ImageHolderView>() {
                    @Override
                    public ImageHolderView createHolder() {
                        return new ImageHolderView();
                    }
                }, imgList);
        if (imgList.size() > 1) {
            //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
            convenientBanner.setPageIndicator(new int[]{R.drawable.small_indicator, R.drawable.small_indicator_focused})
                    //设置指示器的方向
                    .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT);
            convenientBanner.startTurning(3000);
        } else {
            convenientBanner.setManualPageable(false);//设置不能手动影响
        }
//        List<String> noticeList = new ArrayList<>();
//        noticeList.add("杨旭东收到客户表扬");
//        noticeList.add("杨旭东荣获新人王");
//        noticeList.add("杨旭东荣获季度之星");
//        noticeList.add("杨旭东荣获年度优秀员工");
//        noticeList.add("杨旭东荣获年度优秀主管");
//        noticeList.add("杨旭东升职了");
//        noticeList.add("杨旭东迎娶白富美");
//        for (int j = 0; j < noticeList.size(); j++) {
//            TextView tv = new TextView(getActivity());
//            tv.setSingleLine();
//            tv.setEllipsize(TextUtils.TruncateAt.END);
//            tv.setGravity(Gravity.CENTER_VERTICAL);
//            tv.setTextColor(getResources().getColor(R.color.free_ui_dark_gold_text_gray));
//            tv.setTextSize(14);
//            tv.setText(noticeList.get(j));
//            tv.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                }
//            });
//            flipper.addView(tv);
//        }
//        flipper.setInAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.viewflipper_push_up_in));
//        flipper.setOutAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.viewflipper_push_up_out));
//        flipper.startFlipping();
        /**
         * 初始化顶部视图
         */
        toolbar.inflateMenu(R.menu.toolbar_menu);
        SearchView searchView = toolbar.findViewById(R.id.action_search_kl);
        searchView.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }

    private void requestData() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                loadComplete(false);
            }
        }, 3000);
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {

        }
    }

    @Override
    public void onResume() {
        super.onResume();
        //开始自动翻页
        if (imgList != null && imgList.size() > 1) {
            convenientBanner.startTurning(3000);
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        //停止翻页
        convenientBanner.stopTurning();
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.ivSetting,R.id.llStartWork, R.id.llEndWork, R.id.llCancelWork, R.id.llRepairEqp, R.id.llEqpChangeThing, R.id.llEqpCheck, R.id.llPack, R.id.llUnPack, R.id.llIntoDepot, R.id.llIEqpSearch, R.id.llILotSearch, R.id.llIDepotSearch})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivSetting:
                startActivity(new Intent(getActivity(), SettingActivity.class));
                break;
            case R.id.llStartWork:
                startActivity(new Intent(getActivity(), StartWorkActivity.class));
                break;
            case R.id.llEndWork:
                startActivity(new Intent(getActivity(), EndWorkActivity.class));
                break;
            case R.id.llCancelWork:
                startActivity(new Intent(getActivity(), AbortActivity.class));
                break;
            case R.id.llRepairEqp:
                startActivity(new Intent(getActivity(), EqpRepairActivity.class));
                break;
            case R.id.llEqpChangeThing:
                startActivity(new Intent(getActivity(), ChangeThingListActivity.class));
                break;
            case R.id.llEqpCheck:
                startActivity(new Intent(getActivity(), CheckActivity.class));
                break;
            case R.id.llPack:
                startActivity(new Intent(getActivity(), PackPackageActivity.class));
                break;
            case R.id.llUnPack:
                startActivity(new Intent(getActivity(), TakePartActivity.class));
                break;
            case R.id.llIntoDepot:
                startActivity(new Intent(getActivity(), IntoDepotActivity.class));
                break;
            case R.id.llIEqpSearch:
                startActivity(new Intent(getActivity(), SearchEqpActivity.class));
                break;
            case R.id.llILotSearch:
                startActivity(new Intent(getActivity(), SearchLotActivity.class));
                break;
            case R.id.llIDepotSearch:
                startActivity(new Intent(getActivity(), SearchDepotActivity.class));
                break;
        }
    }
}
